<template>
  <div class="listTable ">
    <div v-for="({ title, value, unit }) in data" class="item ">
      <div class="title ">{{ title }}</div>
      <div class="ProgressBar " style="width: 100%">
        <div :style="{ width: unit === '%' ? value + unit : widthFn(value) }" class="ProgressBarItem"></div>
      </div>
      <div class="value ">{{ value }}{{ unit }}</div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { type PropType } from "vue";
const props = defineProps({
  data: {
    type: Array as PropType<Record<'title' | 'value' | 'unit', any>[]>,
    default: () => []
  }
})
const widthFn = (value: number) => {
  return (value / props.data[0].value) * 100 + '%'
}
</script>
<style scoped>
.red {
  border: 1px solid crimson;
}

.listTable {
  width: 100%;
  height: 100%;
}

.item {
  display: flex;
  width: 100%;
  align-items: center;
  flex: 1 1 auto;
  margin-bottom: 10px;
}

.title {
  white-space: nowrap;
  min-width: 100px;
  margin-right: 16px;
  text-align: left;
}

.ProgressBar {
  height: 20px;
  margin-right: 35px;
}

.ProgressBarItem {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #0065E1 0%, #00D5E1 100%);
  transition: all 2s;
}

.value {
  white-space: nowrap;
  width: 50px;
  color: #00D5E1;
  margin-right: 10px;
}
</style>
